﻿@{
	Layout = null;
}

<!DOCTYPE html>

<html>
<head>
	<meta name="viewport" content="width=device-width" />
	<title>Index</title>
	<link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
	<link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
	<link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	<link href="~/Content/Css/animate.css" rel="stylesheet">
	<link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
	<link href="~/Content/Css/plugins/jsTree/style.min.css" rel="stylesheet">
	<style>
		.ibox { margin-bottom: 0px; }
		.ibox-content { padding: 15px 20px 0px 20px; }
	</style>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="ibox float-e-margins">
			<div class="ibox-title">
				<h5>管理员管理</h5>
			</div>
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-10">
						<div class="btn-group">
							<button id="insertBtn" type="button" class="btn btn-outline btn-default">
								<i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
							</button>
							<button id="editBtn" type="button" class="btn btn-outline btn-default">
								<i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
							</button>
							<button id="deleteBtn" type="button" class="btn btn-outline btn-default">
								<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
							</button>
							<button id="refreshBtn" type="button" class="btn btn-outline btn-default">
								<i class="glyphicon glyphicon-refresh" aria-hidden="true"></i>
							</button>
						</div>
					</div>
					<div class="col-sm-2">
						<div class="input-group">
							<input id="SearchKeyWord" type="text" class="form-control" placeholder="请输入要搜索的内容...">
							<span class="input-group-btn">
								<button id="searchBtn" type="button" class="btn btn-primary">
									搜索
								</button>
							</span>
						</div>
					</div>
				</div>
				<div class="row row-lg">
					<div class="col-sm-12">
						<table id="table"></table>
					</div>
				</div>
			</div>
		</div>
		@* 用来传递消息的隐藏域 *@
		<input id="handle_status" value="" hidden="hidden">
	</div>


	<!-- 全局js -->
	<script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
	<script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
	<!-- 自定义js -->
	<script type="text/javascript" src="~/Scripts/content.js?v=1.0.0"></script>
	<script type="text/javascript" src="~/Scripts/common.js"></script>
	<!-- Bootstrap table -->
	<script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
	<script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<!-- layer javascript -->
	<script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>

	<script type="text/javascript">
		var $table = $("#table");

		//自定义的列事件
		//function operateFormatter(value, row, index) {
		//	return [
        //        '<a class="config" href="javascript:void(0)" title="登录配置"><i class="glyphicon glyphicon-cog"></i></a>',
		//	].join("");
		//}

		//window.operateEvents = {
		//	"click .config": function (e, value, row, index) {
		//		parent.layer.open({
		//			type: 2,
		//			title: "登录配置",
		//			shadeClose: false,
		//			shade: 0.4,
		//			area: ["800px", "380px"],
		//			content: "/identity/role/login?staffid=" + value,
		//			end: function () {
		//			}
		//		});
		//	}
		//};

		//初始化Table
		var url = "/identity/role/indexasync";
		var columns = [
			{ field: "selected", width: 38, checkbox: true, },
			{ title: "行号", width: 60, align: "center", formatter: function (value, row, index) { return index + 1; } },
			{ field: "name", title: "名称", width: 300, align: "center" }, 
			{ field: "remark", title: "备注" },
            { title: "权限", align: "center", formatter: FormatterJurisdiction,width:100 }
			//{ field: "id", title: "操作", width: 60, align: "center", events: operateEvents, formatter: operateFormatter }
		];
		var height = 150;
		var params = function (par) {
			var result = {
				pageSize: par.limit,
				pageIndex: (par.offset / par.limit) + 1,
				keyword: $("#SearchKeyWord").val()
			};
			return result;
		};

		$table.initTable(url, columns, height, params);

		//刷新表格数据
		var refreshTable = function () {
			$table.bootstrapTable("refresh");
		}

		//刷新按钮
		$("#refreshBtn").click(function (e) {
			$table.bootstrapTable("refresh");
		});

		//搜索按钮
		$("#searchBtn").click(function (e) {
			$table.bootstrapTable("refresh");
		});
		//权限
		function FormatterJurisdiction(value, row, index) {
		    return [
		            '<a class="kv-file-zoom btn btn-xs btn-primary" href="javascript:void(0)"  onclick="JurisdictionList(' + row.id + ')">',
		            '权限',
		            '</a>  ',
		    ].join('');
		}
		function JurisdictionList(id) {
		    parent.layer.open({
		        type: 2,
		        title: '权限设置',
		        shadeClose: false,
		        shade: 0.4,
		        area: ['1400px', '740px'],
		        content: '/identity/role/Jurisdiction?id=' + id,
		        end: function () {
		            refreshTable();
		        }
		    });

		}
		//插入按钮
		$("#insertBtn").click(function (e) {
			parent.layer.open({
				type: 2,
				title: "添加管理员",
				shadeClose: false,
				shade: 0.4,
				area: ["600px", "250px"],
				content: "/identity/role/insert",
				end: function () {
					refreshTable();
				}
			});
		});

		//编辑按钮
		$("#editBtn").click(function (e) {
			var selected = $table.bootstrapTable("getSelections");

			if (selected.length > 1) {
				layer.msg("一次只能修改一条数据！", { icon: 5, time: 2000 });
				return;
			}

			if (selected.length == 0) {
				layer.msg("请选择您要修改的数据！", { icon: 5, time: 2000 });
				return;
			}
			editData(selected[0].id);
		});

		//打开编辑窗口
		function editData(id) {
			parent.layer.open({
				type: 2,
				title: "修改角色",
				shadeClose: false,
				shade: 0.4,
				area: ["600px", "250px"],
				content: "/identity/role/edit?id=" + id,
				end: function () {
					refreshTable();
				}
			});
		}

		//删除按钮
		$("#deleteBtn").click(function (e) {
			var selected = $table.bootstrapTable("getSelections");
			if (selected.length == 0) {
				layer.msg("请选择您要删除的数据！", { icon: 5, time: 2000 });
				return;
			}

			var arr = [];
			for (var i = 0; i < selected.length; i++) {
				arr.push(selected[i].id);
			}

			var ids = arr.join(",");

			layer.confirm("您确定要删除所选数据吗", {
				btn: ["是的", "取消"] //按钮
			}, function () {
				$.ajax({
					url: "/identity/role/deleteasync",
					type: "post",
					dataType: "json",
					data: { ids: ids },
					success: function (data) {
						//Info,Success,Warning,Error
						var type = data.type;
						if (type == 1) {
							layer.msg(data.content,
                                {
                                	icon: 6, time: 2000
                                },
                                function () {
                                	refreshTable();
                                });
						} else {
							layer.msg(data.content, { icon: 5, time: 2000 });
						}
					}
				});
			}, function () {
				return;
			});
		});
	</script>
</body>

</html>
